package cn.yiyuan.base.service.Imp;


import cn.yiyuan.base.mapper.BaseMapper;
import cn.yiyuan.base.query.BaseQuery;
import cn.yiyuan.base.service.BaseService;
import cn.yiyuan.base.untli.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @user m
 * @project system_boog
 * @date 2023-10-16
 * @package cn.yiyuan.base.servive.Imp
 */
@Service
public class BaseServiceimpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> depMapper;

    @Transactional
    @Override
    public void insert(T dep) {
        depMapper.insert(dep);
    }

    @Transactional
    @Override
    public void delete(Serializable id) {
        depMapper.delete(id);
//        System.out.println(1/0);
    }

    @Transactional
    @Override
    public void update(T dep) {

        depMapper.update(dep);
    }

    @Override
    public List<T> getAll() {
        return depMapper.getAll();
    }

    @Override
    public T getById(Serializable id) {
        return (T) depMapper.getById(id);
    }

    @Override
    public Long queryTotal(BaseQuery baseQuery) {
        return null;
    }


    @Override
    public PageInfo<T> querList(BaseQuery depQuery) {
//        查询总条数
        Long total = depMapper.querTotal(depQuery);
//        查询分页数据
        if (total !=0){
            List<T>list = depMapper.queryList(depQuery);
            return new PageInfo<T>(total,list);
        }
        return new PageInfo<T>();
    }

    //    批量删除
    @Override
    public void pachdelete(List<Long> ids) {
        depMapper.pachdelete(ids);
    }
}
